package com.ruibang.glass.etl.handler.sy;


import com.gitee.Jmysy.binlog4j.core.BinlogEvent;
import com.gitee.Jmysy.binlog4j.core.IBinlogEventHandler;
import com.gitee.Jmysy.binlog4j.springboot.starter.annotation.BinlogSubscriber;
import com.ruibang.glass.etl.entity.BcStationCxzhDetail;
import com.ruibang.glass.etl.entity.BcStationCzDetail;
import com.ruibang.glass.etl.mapper.BcStationCxzhDetailMapper;
import com.ruibang.glass.etl.mapper.BcStationCzDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;

@BinlogSubscriber(clientName = "sy")
public class SYBCStationCzDetaillogEventHandler implements IBinlogEventHandler <BcStationCzDetail>{

    @Autowired
    private BcStationCzDetailMapper bcStationCzDetailMapper;
    @Override
    public void onInsert(BinlogEvent<BcStationCzDetail> event) {
        if(1 > bcStationCzDetailMapper.insert(event.getData())){
            System.out.println("bc_station_cz_detail_2024 插入数据失败:" + event.getData());
        }else
            System.out.println("bc_station_cz_detail_2024 插入数据成功");
    }

    @Override
    public void onUpdate(BinlogEvent<BcStationCzDetail> event)  {
        if(1 > bcStationCzDetailMapper.updateById(event.getData())){
            System.out.println("bc_station_cz_detail_2024 更新数据失败:" + event.getData());
            onInsert(event);
        }else
            System.out.println("bc_station_cz_detail_2024更新数据成功");
    }

    @Override
    public void onDelete(BinlogEvent<BcStationCzDetail> event) {
        if(1 > bcStationCzDetailMapper.deleteById(event.getData())){
            System.out.println("bc_station_cz_detail_2024 删除数据失败:" + event.getData());
        }else
            System.out.println("bc_station_cz_detail_2024 删除数据成功");
    }

    @Override
    public boolean isHandle(String database, String table) {
        return database.equals("hot2_bc2mes") && table.startsWith("bc_station_cz_detail");
    }
}
